package com.durian.finance.controller;

import com.durian.common.core.utils.poi.ExcelUtil;
import com.durian.common.core.web.controller.BaseController;
import com.durian.common.core.web.domain.AjaxResult;
import com.durian.common.core.web.page.TableDataInfo;
import com.durian.common.log.annotation.Log;
import com.durian.common.log.enums.BusinessType;
import com.durian.common.security.annotation.RequiresPermissions;
import com.durian.finance.service.ICfContractService;
import com.durian.financial.api.domain.CfContract;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import javax.servlet.http.HttpServletResponse;
import java.util.List;

/**
 * 租房合同Controller
 * 
 * @author durian
 * @date 2022-06-27
 */
@RestController
@RequestMapping("/contract")
public class CfContractController extends BaseController
{
    @Autowired
    private ICfContractService cfContractService;

    /**
     * 查询租房合同列表
     */
    @RequiresPermissions("finance:contract:list")
    @GetMapping("/list")
    public TableDataInfo list(CfContract cfContract)
    {
        startPage();
        List<CfContract> list = cfContractService.selectCfContractList(cfContract);
        return getDataTable(list);
    }



    /**
     * 导出租房合同列表
     */
    @RequiresPermissions("finance:contract:export")
    @Log(title = "租房合同", businessType = BusinessType.EXPORT)
    @PostMapping("/export")
    public void export(HttpServletResponse response, CfContract cfContract)
    {
        List<CfContract> list = cfContractService.selectCfContractList(cfContract);
        ExcelUtil<CfContract> util = new ExcelUtil<CfContract>(CfContract.class);
        util.exportExcel(response, list, "租房合同数据");
    }

    /**
     * 获取租房合同详细信息
     */
    @RequiresPermissions("finance:contract:query")
    @GetMapping(value = "/{id}")
    public AjaxResult getInfo(@PathVariable("id") Long id)
    {
        return AjaxResult.success(cfContractService.selectCfContractById(id));
    }

    /**
     * 新增租房合同
     */
    @RequiresPermissions("finance:contract:add")
    @Log(title = "租房合同", businessType = BusinessType.INSERT)
    @PostMapping
    public AjaxResult add(@RequestBody CfContract cfContract)
    {
        return toAjax(cfContractService.insertCfContract(cfContract));
    }

    /**
     * 修改租房合同
     */
    @RequiresPermissions("finance:contract:edit")
    @Log(title = "租房合同", businessType = BusinessType.UPDATE)
    @PutMapping
    public AjaxResult edit(@RequestBody CfContract cfContract)
    {
        return toAjax(cfContractService.updateCfContract(cfContract));
    }

    /**
     * 删除租房合同
     */
    @RequiresPermissions("finance:contract:remove")
    @Log(title = "租房合同", businessType = BusinessType.DELETE)
	@DeleteMapping("/{ids}")
    public AjaxResult remove(@PathVariable Long[] ids)
    {
        return toAjax(cfContractService.deleteCfContractByIds(ids));
    }
}
